<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('抽奖奖品列表')" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="lottery-form">
					<div class="select-list">
						<ul>
							<li>
								姓名：<input type="text" name="psnName"/>
							</li>
							<li>
								联系电话：<input type="text" name="tel"/>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()" id="btnSearch"><i class="fa fa-search"></i>&nbsp;搜索</a>
								<a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<form id="lottery-prize-form">
				<input type="hidden" name="lotteryId" id="lotteryId" th:value="${lotteryId}"/>
			</form>
			<div class="btn-group-sm" id="toolbar" role="group">
				<a class="btn btn-success" id="addlotteryResult">
	                <i class="fa fa-plus"></i> 新增
	            </a>
	        </div>
	        
	        <div class="col-sm-12 select-table table-striped">
			    <table id="bootstrap-table-lottery-prize"></table>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<script th:inline="javascript">
		var editFlag = [[${@permission.hasPermi('biz:lottery:edit')}]];
		var removeFlag = [[${@permission.hasPermi('biz:lottery:remove')}]];
		var prefix = ctx + "biz/lotteryResult";


		$(function() {
		    var options = {
				id: "bootstrap-table-lottery-prize",
		        url: prefix + "/list",
				showSearch: false,
				showRefresh: false,
				showToggle: false,
				showColumns: false,
				pagination: false,
		        createUrl: prefix + "/add/" + $("#lotteryId").val(),
		        updateUrl: prefix + "/edit/{id}",
		        removeUrl: prefix + "/remove",
		        exportUrl: prefix + "/export",
		        sortName: "lotteryResultId",
		        modalName: "中奖",
		        columns: [
		        /*{
		            field: 'lotteryId',
		            title: '抽奖活动ID'
		        },*/
		        {
		            field: 'lotteryPrizeTitle',
		            title: '奖项名称',
		            sortable: true
		        },
		        {
		            field: 'lotteryPrizeName',
		            title: '奖品名称',
		            sortable: true
		        },
		        {
		            field: 'tel',
		            title: '中奖人联系电话',
		            sortable: true
		        },
		        {
		            field: 'psnName',
		            title: '中奖人姓名',
		            sortable: true
		        },
		        {
		            field: 'lotteryResultType',
		            title: '中奖方式',
		            sortable: true,
					formatter: function(value, row, index) {
						return row.lotteryResultType == '1' ? '系统添加' : '抽中';
					}
		        },
		        {
		            field: 'lotteryLogId',
		            title: '是否抽取',
		            sortable: true,
					formatter: function(value, row, index) {
						return row.lotteryLogId ? '已被抽取' : '未被抽取';
					}
		        },
		        {
		            title: '操作',
		            align: 'center',
		            formatter: function(value, row, index) {
						var actions = [];
						actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="removeResult(\'' + row.lotteryLogId +  '\'\,\'' + row.lotteryResultId + '\')"><i class="fa fa-remove"></i>删除</a> ');
						return actions.join('');
		            }
		        }]
		    };
		    $.table.init(options);

		    $("#addlotteryResult").click(function () {
				var url = prefix + '/add/' + $("#lotteryId").val();
				layer.open({
					type: 2,
					area: [ '600px', '450px'],
					fix: false,
					//不固定
					maxmin: true,
					shade: 0.3,
					title: "添加中奖人信息",
					content: url,
					btn: ['确定', '关闭'],
					// 弹层外区域关闭
					shadeClose: true,
					yes: function(index, layero) {
						var iframeWin = layero.find('iframe')[0];
						iframeWin.contentWindow.submitHandler(index, layero);
						$.table.refresh();
					},
					cancel: function(index) {
						$.table.refresh();
					},
					success: function () {
						$(':focus').blur();
					}
				});
			});
		});

		function removeResult(lotteryLogId, lotteryResultId) {
			var msg = "确定删除该条中奖信息吗？";
			if (lotteryLogId) {
				msg = "本条中奖信息已经有人抽中，删除后对应的抽奖结果也会删除，确认删除？";
			}
			$.modal.confirm(msg, function() {
				var config = {
					url: "/biz/lotteryResult/remove",
					type: "post",
					dataType: "json",
					data: { "ids": lotteryResultId },
					beforeSend: function () {
						$.modal.loading("正在处理中，请稍候...");
					},
					success: function(result) {
						$.modal.closeLoading();
						if (result.code == 0) {
							$.modal.msgSuccess(result.msg);
						} else {
							$.modal.alertError(result.msg);
						}
						$("#btnSearch").click();
					}
				};
				$.ajax(config)
			});
		}
	</script>
</body>
</html>